package com.jmx.controller;

import com.jmx.pojo.ScoreDistribution;
import com.jmx.pojo.ScoreDistributionOV;
import com.jmx.service.IScoreDistribution;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@CrossOrigin
public class IndexController {
    @Autowired(required = false)
    private IScoreDistribution scoreDistribution;

    @RequestMapping("Hello")
    @ResponseBody
    public String Hello(){
        return "home";
    }

    @RequestMapping("scoreDistribution")
    @ResponseBody
    public List<ScoreDistributionOV> queryScoreDistribution(){
        List<ScoreDistribution> scoreDistributions = scoreDistribution.queryScoreDistribution();
        List<ScoreDistributionOV> scoreDistributionovs = new ArrayList<ScoreDistributionOV>();
        for (ScoreDistribution sd:scoreDistributions) {
            scoreDistributionovs.add(new ScoreDistributionOV(sd.getCountDistribution(),sd.getStage()));
        }
        return scoreDistributionovs;
    }
}
